<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head >
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>宠物新增</title>
    <link rel="stylesheet" href="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.css">
    <link rel="stylesheet" href="../../static/lib/editormd/css/editormd.min.css">
    <link rel="stylesheet" href="../../static/css/me.css">
</head>
<body>
<!--导航-->
<nav class="ui inverted attached segment m-padded-tb-mini m-shadow-small" >
    <div class="ui container">
        <div class="ui inverted secondary stackable menu">
            <h2 class="ui teal header item">管理后台</h2>
            <a href="#" th:href="@{/admin/pets}" class="m-item item m-mobile-hide active"><i class="mini home icon"></i>&nbsp;宠物</a>
            <a href="#" th:href="@{/admin/types}" class=" m-item item m-mobile-hide"><i class="mini idea icon"></i>分类</a>
            <a href="#" th:href="@{/admin/users}" class="m-item item m-mobile-hide"><i class="mini tags icon"></i>&nbsp;用户</a>
            <div class="right m-item m-mobile-hide menu">
                <div class="ui dropdown  item">
                    <div class="text">
                        <img class="ui avatar image" src="https://unsplash.it/100/100?image=1005">
                        超级管理员 郭江富
                    </div>
                    <i class="dropdown icon"></i>
                    <div class="menu">
                        <a href="#" class="item">注销</a>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <a href="#" class="ui menu toggle black icon button m-right-top m-mobile-show">
        <i class="sidebar icon"></i>
    </a>
</nav>
<div class="ui attached pointing menu">
    <div class="ui container">
        <div class="right menu">
            <a href="#" th:href="@{/admin/blogs/input}" class="teal active item">发布</a>
            <a href="#" th:href="@{/admin/blogs}" class="item">列表</a>
        </div>
    </div>
</div>

<!--中间内容-->
<div  class="m-container m-padded-tb-big">
    <div class="ui container">
        <form id="blog-form" action="#" th:action="@{/admin/addPet}" method="post" class="ui form"  enctype="multipart/form-data">
            <div class="required field">
                <div id="md-content" style="z-index: 1 !important;">
                    <textarea placeholder="博客内容" name="content" style="display: none" ></textarea>
                </div>
            </div>

            <div class="two fields">
                <div class="required field">
                    <div class="ui left labeled action input">
                        <label class="ui compact teal basic label">种类</label>
                        <div class="ui fluid selection dropdown">
                            <input type="hidden" name="type.id" >
                            <i class="dropdown icon"></i>
                            <div class="default text">种类</div>
                            <div class="menu">
                                <div th:each="type: ${types}" th:text="${type.name}" th:data-value="${type.id}" class="item"  >错误日志</div>
                            </div>
                        </div>
                    </div>
                </div>

                <div class="required field">
                    <div class="ui left labeled action input">
                        <label class="ui compact teal basic label">年龄</label>
                        <input type="text" name="age" th:value="${pet==null} ? '': ${pet.age}" placeholder="年龄" onkeyup="this.value=this.value.replace(/\D|^0/g,'')" onafterpaste="this.value=this.value.replace(/\D|^0/g,'')" maxlength="2">
                    </div>
                </div>
                <div class="required field">
                    <div class="ui left labeled action input">
                        <label class="ui compact teal basic label">姓名</label>
                        <input type="text" name="name" th:value="${pet == null} ? '': ${pet.name}" placeholder="姓名" >
                    </div>
                </div>
                <div class="required field ui selection dropdown">
                    <input type="hidden" name="male">
                    <i class="dropdown icon"></i>
                    <div class="default text">性别</div>
                    <div class="menu">
                        <div class="item"  data-value="雄">雄性</div>
                        <div class="item" data-value="雌">雌性</div>
                    </div>
                </div>
                <div class=" field required">
                    <div class="ui left labeled action input">
                        <label class="ui compact teal basic label">价格</label>
                                <input type="text" th:value="${pet == null} ? '' : ${pet.price}" name="price" id="price" placeholder="￥"  onkeyup="this.value=/^[0-9]*\.?[0-9]{0,2}$/.test(this.value) ? this.value : this.value.substring(0,this.value.length-1)"/>
                    </div>
                </div>
            </div>
            <div class="required field">
                <div class="ui left labeled input">
                    <label class="ui teal basic label">图片</label>
                    <input type="file" name="picture" enctype="multipart/form-data">
                </div>
            </div>
            <div class="required field">
                <textarea name="description" placeholder="宠物描述..." th:text="${pet == null} ? '' : ${pet.description}" maxlength="200"></textarea>
            </div>


            <div class="ui error message"></div>
            <div class="ui right aligned container">
                <button type="button" class="ui button" onclick="window.history.go(-1)" >返回</button>
                <button type="button" id="publish-btn" class="ui teal button">发布</button>
            </div>
        </form>
        <div class="ui success message" th:unless="${#strings.isEmpty(message)}">
            <i class="close icon"></i>
            <div class="header">提示：</div>
            <p th:text="${message}">恭喜，操作成功！</p>
        </div>

    </div>
</div>

<br>
<br>
<!--底部footer-->
<footer  class="ui inverted vertical segment m-padded-tb-massive">
    <div class="ui center aligned container">
        <div class="ui inverted divided stackable grid">
            <div class="three wide column">
                <div class="ui inverted link list">
                    <div class="item">
                        <img src="../../static/images/wechat.jpg" class="ui rounded image" alt="" style="width: 110px">
                    </div>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced " >宠物商店</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item m-text-thin">用户故事（User Story）</a>
                    <a href="#" class="item m-text-thin">用户故事（User Story）</a>
                    <a href="#" class="item m-text-thin">用户故事（User Story）</a>
                </div>
            </div>
            <div class="three wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced ">联系我</h4>
                <div class="ui inverted link list">
                    <a href="#" class="item m-text-thin">Email：420919469@qq.com</a>
                    <a href="#" class="item m-text-thin">QQ：420919469</a>
                </div>
            </div>
            <div class="seven wide column">
                <h4 class="ui inverted header m-text-thin m-text-spaced ">PetStore</h4>
                <p class="m-text-thin m-text-spaced m-opacity-mini">一个简单的宠物商店。。。</p>
            </div>
        </div>
        <div class="ui inverted section divider"></div>
        <p class="m-text-thin m-text-spaced m-opacity-tiny">Copyright © 2020 - 2099 GuoJiangfu Designed by GuoJiangfu</p>
    </div>

</footer>

<script src="https://cdn.jsdelivr.net/npm/jquery@3.2/dist/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/semantic-ui/2.2.4/semantic.min.js"></script>

<script>

    //初始化Markdown编辑器

    var contentEditor;
    $(function() {
        contentEditor = editormd("md-content", {
            width   : "100%",
            height  : 640,
            syncScrolling : "single",
//        path    : "../static/lib/editormd/lib/"
            path    : "/lib/editormd/lib/"
        });
    });
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide');
    });

    $('.ui.dropdown').dropdown({
        on : 'hover'
    });

    $('#save-btn').click(function () {
        $('[name="published"]').val(false);
        $('#blog-form').submit();
    });


    $('#publish-btn').click(function () {
        $('[name="published"]').val(true);
        $('#blog-form').submit();
    });



    $('.ui.form').form({
        fields : {
            typeId : {
                identifier: 'type.id',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入宠物分类'
                }]
            },
            age : {
                identifier: 'age',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入宠物年龄'
                }]
            },
            gender : {
                identifier: 'gender',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入宠物性别'
                }]
            },
            price : {
                identifier: 'price',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入价格'
                }]
            },

            firstPicture : {
                identifier: 'picture',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入宠物图片'
                }]
            },
            description : {
                identifier: 'description',
                rules: [{
                    type : 'empty',
                    prompt: '标题：请输入宠物描述'
                }]
            }
        }
    });

</script>
</body>
</html>